<?php

namespace app\home\model;
use think\Model;
use think\Db;

class ArticleModel extends Model
{

    protected $name = 'article';

    /**
     * [getAllCate 获取文章]
     * @author [张家恒] [852952656@qq.com]
     */
    public function getOneNews($id)
    {
        return Db::name('article')
                ->field('id,title,content,create_time,update_time,writer,remark,views,keyword')
                ->where(array('id' => $id))
                ->find();


    }

    /**
     * fetchSuiJiNews [ 随机取出10条新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function fetchSuiJiNews()
    {
        return  Db::name('article')
                ->order("rand()")
                ->field('id,title')
                ->limit(10)
                ->select();

    }

    /**
     * NextArticle [ 下一条新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return array|false|\PDOStatement|string|Model
     * @param $id
     */
    public function NextArticle($id)
    {
        return  Db::name('article')
            ->where("id",'>',$id)
            ->field('id,title,remark ')
            ->order('id asc')
            ->limit('1')
            ->find();
    }

    /**
     * getIdWherePilise [ 取出当前id为政策法规的全部新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return array|false|\PDOStatement|string|Model
     * @param $id
     */
    public function getIdWherePilise($id,$p_id)
    {
        return  Db::name('article')
            ->where(array('cate_id' => $p_id,'id' => $id))
            ->field('id,title,remark,content,update_time,writer')
            ->order('id desc')
            ->find();

    }


    /**
     * getAllPoliseTitleAndId [取出政策法规所有的标题跟ID  ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getAllPoliseTitleAndId($pid)
    {
        return  Db::name('article')
                ->where(array('cate_id' => $pid))
                ->field('id,title')
                ->order('id desc')
                ->select();
    }


    /**
     * getPoliseNewOne [ 取出最新的一个政策法规 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getPoliseNewOne($p_id)
    {
        return  Db::name('article')
                ->where(array('cate_id' => $p_id))
                ->where('id','<','100000')
                ->field('id')
                ->order('id desc')
                ->limit('1')
                ->find();
    }

    /**
     * fetchCateIDNewsAll [ 根据ID查询当前在ID内的所有新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function fetchCateIDNewsAll($id)
    {
        return Db::name('article')
                ->where('cate_id','in',$id)
                ->order('id desc')
                ->paginate(4);
    }


    /**
     * fetchCateIDNewsAll [ 根据ID查询当前在ID内的所有新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function findAllTenTuiJianNews()
    {
        return Db::name('article')
                ->where('is_tui',1)
                ->order('id desc')
                ->limit(10)
                ->select();
    }


     /**
     * fetchCateIDNewsAll [ 根据ID查询当前在ID内的所有新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getOneNewTuiJianNews()
    {
        return Db::name('article')
                ->where('is_tui',1)
                ->order('id desc')
                
                ->find();
    }










}